import 'package:flutter/material.dart';
import 'package:flutter_common/config/config.dart';

class MsgDialog {
  static void show(BuildContext context,
      {String title, String content, Function confirm}) {
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return WillPopScope(
            child: MsgDialogContent(
              context,
              title: title,
              content: content,
              confirm: confirm,
            ),
            onWillPop: () async {
              return Future.value(false);
            });
      },
    );
  }
}

class MsgDialogContent extends StatelessWidget {

  BuildContext context;
  String title;
  String content;
  Function confirm;

  MsgDialogContent(this.context, {this.title, this.content, this.confirm});

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      title: Text(
        title != null ? title : '提示',
        style: TextStyle(fontSize: 18),
      ),
      content: Container(
        child: Text(
          content,
          style: TextStyle(fontSize: 14),
        ),
      ),
      actions: <Widget>[
        FlatButton(
          child: Text(
            '確定',
            style: TextStyle(color: Config.titleBarColor, fontSize: 12),
          ),
          onPressed: () {
            Navigator.pop(context);
            if (confirm != null) {
              confirm();
            }
          },
        )
      ],
    );
  }
}
